﻿@{
    ViewBag.Title = "单据分组";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
<div class="layui-tab layui-tab-brief" lay-filter="user">
    <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 5px 0;">
        <form action="" class="layui-form">
            <div class="layui-form-item" style="margin: 10px 0 0;">
                <label class="layui-form-label" style="width: auto; padding-right: 5px;">名称筛选：</label>
                <div class="layui-input-inline">
                    <input type="text" name="keyWord" class="layui-input">
                </div>
                <button type="button" class="layui-btn searchButton">搜索</button><a class="layui-btn" href="javascript:ShowPage('/Admin/TableInfo/Create','添加表格')">添加表格</a>
            </div>
        </form>

        <table class="layui-table" lay-data="{url:'GetData', cellMinWidth: 80, page: true,limit:200}" id="resultList" lay-filter="resultList">
            <thead>
                <tr>
                    <th lay-data="{field:'ID', width:80}">ID</th>
                    <th lay-data="{field:'Name',edit: 'text'}">名称</th>
                    <th lay-data="{fixed:'right', width:320, align:'center', toolbar: '#barDemo'}">操作</th>
                </tr>
            </thead>
        </table>
        <script type="text/html" id="barDemo">
            <a class="layui-btn layui-btn-primary layui-btn-xs" lay-href="/Admin/TableInfo/Edit?id={{d.ID}}">修改表格</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" href="javascript:DeleteItemt('{{d.ID}}')">删除</a>
        </script>

    </div>
</div>
<script type="text/javascript">
    
    function DeleteItemt(id) {
        layer.confirm('您正在进行删除表格操作', {
            btn: ['是的,我要删除当前表格', '不小心点错了'] //按钮
        }, function () {
            var url = "/Admin/TableInfo/Delete?id=" + id;
            $.getJSON(url, function (data) {
                if (data.State === 200) {
                    $(".layui-laypage-btn")[0].click();
                }
                else {
                    layer.msg(data.Msg);
                }
            });
        }, function () {

        });
    }
 
    layui.use(['table','form'], function () {
        var table = layui.table;
        var form = layui.form;
        
        form.on('checkbox(IsCustomView)', function (data) {
            var isChecked = data.elem.checked;
            var mydata = data;
            url = "/Admin/CustomForm/SetIsCustomView?id=" + data.value + "&isCustomView=" + data.elem.checked;
            $.getJSON(url, function (data) {
                if (data.State == 200) {
                    if (isChecked) {
                        layer.msg("自定义模版设置成功", { time: 500 });
                    }
                    else {
                        layer.msg("自定义模版取消成功", { time: 500 });
                    }
                }
                else {
                    console.log($(mydata.elem));
                    if (isChecked) {
                        $(elem).prop("checked", false);
                    }
                    else {
                        $(elem).prop("checked", true);
                    }
                    layer.msg(data.Msg);
                }
            });
        });
        form.on('checkbox(HasProcessingFlow)', function (data) {
            var isChecked = data.elem.checked;
            var mydata = data;
            url = "/Admin/CustomForm/SetHasProcessingFlow?id=" + data.value + "&hasProcessingFlow=" + data.elem.checked;
            $.getJSON(url, function (data) {
                if (data.State == 200) {
                    if (isChecked) {
                        layer.msg("处理流程设置成功", { time: 500 });
                    }
                    else {
                        layer.msg("处理流程取消成功", { time: 500 });
                    }
                }
                else {
                    console.log($(mydata.elem));
                    if (isChecked) {
                        $(elem).prop("checked", false);
                    }
                    else {
                        $(elem).prop("checked", true);
                    }
                    layer.msg(data.Msg);
                }
            });
        });

        

        table.on('edit(resultList)', function (obj) {
            if (obj.field === 'Sort') {
                var url = "/Admin/TableInfo/SetColumnNumber?id=" + obj.data.ID + "&sort=" + obj.value;
                $.getJSON(url, function (data) {
                    if (data.State == 200) {
                        layer.msg("表格列数设置成功", { time: 500 });
                    }
                    else {
                        layer.msg(data.Msg);
                    }
                });
            }
        });

    }); 

</script>


